package com.dkcrow.spring.transaction.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl{

	@Autowired SqlSession sqlSession;
	@Autowired SqlSession localSqlSession;
	
//	@Autowired JdbcTemplate jdbcTemplate;
//	
//	public void insertUser(String id, String name, int age) {
//		jdbcTemplate.update("insert into my_user(id,name,age) values(?,?,?)",new Object[]{id,name,age});
//	}
//	
//	public void deleteAllUser(){
//		jdbcTemplate.update("delete from my_user");
//	}
	
	public List<Map<String, Object>> selectUserCompare() {
		return sqlSession.selectList("USER.selectUser");
	}
	
	public void insertUser(String id, String name, int age) {
		Map<String,Object>param = new HashMap<String,Object>();
		param.put("id", id);
		param.put("name", name);
		param.put("age", age);
		sqlSession.insert("USER.insertUser",param);
	}
	
	public void insertLocalUser(String id, String name, int age) {
		Map<String,Object>param = new HashMap<String,Object>();
		param.put("id", id);
		param.put("name", name);
		param.put("age", age);
		localSqlSession.insert("USER.insertUser",param);
	}
	
	public void deleteAllUser(){
		sqlSession.insert("USER.deleteAllUser");
		localSqlSession.insert("USER.deleteAllUser");
	}
}
